﻿using IterationLife.ContentResources.Models;
using Util;

namespace IterationLife.PlatformBackEnd.AppServices.Dtos.ContentResources {
    /// <summary>
    /// 内容资源分类数据传输对象扩展
    /// </summary>
    public static class ContentResourceCategoryDtoExtension {        
        /// <summary>
        /// 转换为内容资源分类实体
        /// </summary>
        /// <param name="dto">内容资源分类数据传输对象</param>
        public static ContentResourceCategory ToEntity( this ContentResourceCategoryDto dto ) {
            if( dto == null )
                return new ContentResourceCategory();
            return new ContentResourceCategory( dto.Id.ToGuid() ,dto.Path,dto.Level.SafeValue() ) {
                ParentId = dto.ParentId.ToGuidOrNull(),
                Code = dto.Code,
                Name = dto.Name,
                Enabled = dto.Enabled,
                SortId = dto.SortId,
                CreationTime = dto.CreationTime,
                CreatorId = dto.CreatorId,
                LastModificationTime = dto.LastModificationTime,
                LastModifierId = dto.LastModifierId,
                IsDeleted = dto.IsDeleted,
                Version = dto.Version
            };
        }
        
        /// <summary>
        /// 转换为内容资源分类数据传输对象
        /// </summary>
        /// <param name="entity">内容资源分类实体</param>
        public static ContentResourceCategoryDto ToDto( this ContentResourceCategory entity ) {
            if( entity == null )
                return new ContentResourceCategoryDto();
            return new ContentResourceCategoryDto {
                Id = entity.Id.SafeString(),
                ParentId = entity.ParentId.SafeString(),
                Code = entity.Code,
                Name = entity.Name,
                Level = entity.Level,
                Enabled = entity.Enabled,
                SortId = entity.SortId,
                Path = entity.Path,
                CreationTime = entity.CreationTime,
                CreatorId = entity.CreatorId,
                LastModificationTime = entity.LastModificationTime,
                LastModifierId = entity.LastModifierId,
                IsDeleted = entity.IsDeleted,
                Version = entity.Version
            };
        }
    }
}
